<template>
    <my-recommend :infoData="info_list" @golist="listPage" :isNow="isNull"></my-recommend>
</template>
<style lang="scss" scoped>
</style>
<script>
import axios from "axios"
import { useStore } from 'vuex'
import MyRecommend from '@/components/MyRecommend.vue'
import store  from '../../store/index'
import {ref} from 'vue'
export default {
    components:{
        MyRecommend
    },
    computed:{
        info_list(){
            return store.state.list_n3
        }
    },
    setup(){
        const usestore = useStore() 
        // 获取所有关注数据
        axios.get("http://127.0.0.1:4523/m1/1231339-0-default/myZcool/infoList/3")
        .then((res)=>{
            // 初始化所有关注数据
            usestore.dispatch('set3',res.data)
            // 设计所有关注第一页数据
            store.state.list_n3 = []
            store.state.info_list3.data.forEach((item,index) => {
                if(index<40){
                    store.state.list_n3.push(item)
                }
            })
        })
        .catch(()=>{
            console.log("not find")
        })


        // 数据分页
        let isNull = ref(false)
        let listPage = (listId)=>{
            store.state.list_n3 = []
            let min = (listId-1)*40
            let max = listId*40
            store.state.info_list3.data.forEach((item,index) => {
                if(index>=min&&index<max){
                    store.state.list_n3.push(item)
                    
                }
            })
            if(store.state.list_n3.length == 0){
                isNull.value = true
            }
            else{
                isNull.value = false
            }
        }
        return{
            listPage,
            isNull
        }
    }
}
</script>